package com.des1gn.serviceb.controller;

import com.des1gn.serviceb.config.MybatisContext;
import com.des1gn.serviceb.dao.AMapper;
import com.des1gn.serviceb.entity.A;
import com.des1gn.serviceb.entity.BVo;
import com.des1gn.serviceb.service.TestService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName TestController
 * @Description TODO
 * @Author Des1gn
 * @Date 2021/9/29 13:52
 * @Version 1.0
 **/
@RestController
@RequiredArgsConstructor
public class TestController {

    private final AMapper aMapper;
    private final TestService testService;
    private final MybatisContext mybatisContext;

    @GetMapping("test")
    public String test(String ack){
        aMapper.updateName();
        if (ack.equals("rollback")){
            System.out.println(1/0);
        }
        return ack;
    }


    @GetMapping("testGetB")
    public List<BVo> testGetB(){
        return testService.getB();
    }

    @GetMapping("getById")
    public A getById(){
        return aMapper.getById();
    }

    @GetMapping("reload")
    public void reload() throws IOException {
        mybatisContext.reloadMapper();
    }


}
